var Core = {
	/*
	API_VER:"http://192.168.1.102:3000",
					IMG_VER:"http://192.168.1.102:3000/upload/",
					ATTACH_VER:"http://192.168.1.102:3000/upload/",*/
	
	
	
    //120.25.151.61  123.57.8.173
	
	

	API_VER:"http://120.25.151.61",
			IMG_VER:"http://120.25.151.61/upload/",
			ATTACH_VER:"http://120.25.151.61/upload/",
			NEW_IMG:"http://120.25.151.61/news/img",
	
	

	
	
	
	VERSION:"1.0.1",
	offsetDate: function(UTCTime) {
		if (UTCTime == "" || UTCTime == undefined)
			return "";
		var now = new Date();
		var date = new Date(UTCTime);

		var offsetMS = parseInt((now.getTime() - date.getTime()) / 1000 / 60);
		var ju=CurrentUser.category==30?"刚刚":"Just";
		var min=CurrentUser.category==30?"分钟前":"Minutes ago";
		if (offsetMS < 5)
			return ju;
		else if (offsetMS < 60)
			return offsetMS + min;
		else if (now.pattern("yyyy-MM-dd") == date.pattern("yyyy-MM-dd"))
			return date.pattern("HH:mm");
		else if (now.pattern("yyyy") == date.pattern("yyyy"))
			return date.pattern("yyyy-M-d")
		else
			return date.pattern("yyyy-M-d");
	},
	id2url: function(obj, from) {
		var url;
        if (from == "photo") 
            url = Core.IMG_VER + obj;
        else if (obj.photo) 
            url = Core.IMG_VER + obj.photo;
        else 
            url = "../img/chinese.png";
        return url;
	},
	check: function() {
		if ($("#phone").val() == "") {
			$alertCE(CH_EN.phoneNotNull[lan]);
			return false;
		}
		if ($("#pwd,#password").val() == "") {
			$alertCE(CH_EN.passwordNotNull[lan]);
			return false;
		}
		if ($("#name").val() == "") {
			$alertCE("名字不能为空/The Name is Empty");
			return false;
		}
		return true;
	}
}
function checkMobile(str){
    var re = /^1\d{10}$/;
    if (!re.test(str)) {
        $alert("请输入正确的手机号码");
        return false;
    } else {
       return true;
    }
}
function checkEmail(str){
    var re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
    if(!re.test(str)){
       alert("请输入正确的邮箱");
       return false;
	} else
		return true;
}
function jieUrljing(){  
    var a=window.location.href.substring(window.location.href.indexOf('#')+1);  
    if(a!==undefined&&a!==''&&window.location.href.indexOf('#')>0){  
        return a;
    }  
}
function showLoading(id){
	return;
	if (!id)
		id = "body";
	else
		id = "#" + id;
	var loading = 	'<div id="loading" class="fakeloader" style="position: fixed; width: 100%; height: 100%; top: 0px; left: 0px;z-index: 999999; background-color:black;opacity:0.6;">' + 
				    '    <div class="fl spinner2" style="position: absolute; left: 45%; top: 45%;">' + 
				    '        <div class="spinner-container container_1">' + 
				    '            <div class="circle1"></div>' + 
				    '            <div class="circle2"></div>' + 
				    '            <div class="circle3"></div>' + 
				    '            <div class="circle4"></div>' + 
				    '        </div>' + 
				    '        <div class="spinner-container container_2">' + 
				    '            <div class="circle1"></div>' + 
				    '            <div class="circle2"></div>' + 
				    '            <div class="circle3"></div>' + 
				    '            <div class="circle4"></div>' + 
				    '        </div>' + 
				    '        <div class="spinner-container container_3">' + 
				    '            <div class="circle1"></div>' + 
				    '            <div class="circle2"></div>' + 
				    '            <div class="circle3"></div>' + 
				    '            <div class="circle4"></div>' + 
				    '        </div>' + 
				    '    </div>' + 
				    '</div>';
	$(id).append(loading);			    
}
function hideLoading(){
	return;
	$("#loading").remove();
}

Array.prototype.pushh = function(val) {
	this.push(val);
	return this;
}
Array.prototype.find = function(key, val) {
	if (key == "") {
		for (var i = 0; i < this.length; ++i) {
			if (this[i] == val)
				return i;
		}
	} else {
		for (var i = 0; i < this.length; ++i) {
			if (this[i][key] == val)
				return this[i];
		}
	}
	return -1;
}
Array.prototype.remove = function(val) {
	if (this.find(val) >= 0)
		this.splice(this.find(val), 1);
}
String.prototype.replaceAll = function(str1, str2) {
	return this.replace(/str1/g, str2);
}

/** * 对Date的扩展，将 Date 转化为指定格式的String * 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q)
    可以用 1-2 个占位符 * 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) * eg: * (new
    Date()).pattern("yyyy-MM-dd hh:mm:ss.S")==> 2006-07-02 08:09:04.423      
 * (new Date()).pattern("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04      
 * (new Date()).pattern("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04      
 * (new Date()).pattern("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04      
 * (new Date()).pattern("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
 */

Date.prototype.pattern = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份
		"d+": this.getDate(), //日
		"h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时 (12小时制)
		"H+": this.getHours(), //小时 (24小时制)
		"m+": this.getMinutes(), //分
		"s+": this.getSeconds(), //秒
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度
		"S": this.getMilliseconds() //毫秒
	};
	var week = {
		"0": "/u65e5",
		"1": "/u4e00",
		"2": "/u4e8c",
		"3": "/u4e09",
		"4": "/u56db",
		"5": "/u4e94",
		"6": "/u516d"
	};
	if (/(y+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}
	if (/(E+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
	}
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		}
	}
	return fmt;
}


//获取这个月一共多少天
function GetDaysInMonth(year, month){
      month = parseInt(month,10)+1;
      var temp = new Date(year+"/"+month+"/0");
      return temp.getDate();
}

function ShowLoading(isShow) {
	var html = '';
    var height = $('body').height();
    var width = $('body').width();
    html = '<div class="loading ub ub-ac ub-pc" style="height:'+height+'px;width:'+width+'px;position:absolute;top:0;left:0;z-index:9999;"><div class="uw4 uh4 im_loading ub_img"></div></div>';
    $("body").append(html);
}

function HideLoading() {
	$(".loading").remove();
}

var ajaxUrl = {};
function $ajax(opt) {
	opt.url = Core.API_VER+opt.url;
	if (ajaxUrl[opt.url]) {
		return false;
	}
	ajaxUrl[opt.url] = true;
	opt.dataType = "json";
	opt.type = "post";
	opt.cache = false;
	opt.beforeSend = function(){
        ShowLoading();
       // $alert("森");
    };
	opt.error = function(XMLHttpRequest, textStatus) {
		HideLoading();
		var status = XMLHttpRequest.status;
		if (status == 0)
			return;
		else if (status == 500)
			$alert("服务器错误");
		else
			$alert("请检查您的网络。");
	};
	opt.goSuccess = opt.success;
	opt.success = function(res) {
		HideLoading();
		if (res.code) {
			if (res.code != 999){
				$alertCE("用户不存在或密码错误 /User does not exist or wrong password");
				if (res.code == 100){
				    if(GetLS("freeLoginFaile")){
				        OpenNewWin("signupFree");
				    }else{
				        OpenNewWin("signup");
				    }
				}
			}	
		}
		else
			opt.goSuccess(res);
	}
	opt.complete = function() {
		HideLoading();
		delete ajaxUrl[opt.url];
	}
	$.ajax(opt);
}
function $ajaxT(opt) {
    opt.url = Core.API_VER+opt.url;
    if (ajaxUrl[opt.url]) {
        return false;
    }
    ajaxUrl[opt.url] = true;
    opt.dataType = "json";
    opt.type = "post";
    opt.cache = false;
   
    opt.error = function(XMLHttpRequest, textStatus) {
        //HideLoading();
        var status = XMLHttpRequest.status;
        if (status == 0)
            return;
        else if (status == 500)
            $alert("服务器错误");
        else
            $alert("请检查您的网络。");
    };
    opt.goSuccess = opt.success;
    opt.success = function(res) {
        //HideLoading();
        if (res.code) {
            if (res.code != 999){
                $alertCE("用户不存在或密码错误/User does not exist or wrong password");
                if (res.code == 100){
                    if(GetLS("freeLoginFaile")){
                        OpenNewWin("signupFree");
                    }else{
                        OpenNewWin("signup");
                    }
                }
            }   
        }
        else
            opt.goSuccess(res);
    }
    opt.complete = function() {
        //HideLoading();
        delete ajaxUrl[opt.url];
    }
    $.ajax(opt);
}
var CurrentUser = GetLS("user");
var lan = GetLS("language")?GetLS("language"):0;
